package com.manager.controller;

import com.manager.bean.StudentDormitoryExample;
import com.manager.bean.StudentDormitoryKey;
import com.manager.bean.view.StudentDormitoryView;
import com.manager.service.StudentDormitoryService;
import com.manager.service.view.StudentDormitoryViewService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

import com.manager.bean.PageInfo;

/**
 * (StudentDormitory)表控制层
 *
 * @author makejava
 * @since 2021-03-02 20:15:30
 */
@Controller
public class StudentDormitoryController {
    /**
     * 服务对象
     */
    @Resource
    private StudentDormitoryService StudentDormitoryService;

    @Resource
    private StudentDormitoryViewService StudentDormitoryViewService;

    @RequestMapping(value = "/findStudentDormitory")
    public String findStudentDormitory(Model model,Integer Id, String Name, Integer DormitoryId, Integer pageIndex, Integer pageSize) {
        PageInfo<StudentDormitoryView> pi =  StudentDormitoryViewService.findPageInfo(Id,Name,DormitoryId,pageIndex,pageSize);
        model.addAttribute("pi", pi);
        return "StudentDormitory_list";
    }


    @RequestMapping(value = "/exportStudentDormitorylist", method = RequestMethod.POST)
    @ResponseBody
    public List<StudentDormitoryView> exportStudentDormitory() {
        List<StudentDormitoryView> all = StudentDormitoryViewService.getAll();
        return all;
    }


    @RequestMapping("/deleteStudentDormitory")
    @ResponseBody
    public String deleteStudentDormitory(Integer Id) {
        StudentDormitoryService.deleteById(Id);
        return "StudentDormitory_list";
    }


    @RequestMapping(value = "/addStudentDormitory", method = RequestMethod.POST)
    @ResponseBody
    public String addStudentDormitory(@RequestBody StudentDormitoryKey StudentDormitory) {
        StudentDormitoryService.insert(StudentDormitory);
        return "StudentDormitory_list";
    }


    @RequestMapping(value = "/updateStudentDormitory", method = RequestMethod.POST)
    public String updateStudentDormitory(StudentDormitoryKey StudentDormitory) {
        StudentDormitoryService.update(StudentDormitory);
        return "redirect:/findStudentDormitory";
    }


    @RequestMapping("/findStudentDormitoryById")
    public String findStudentDormitoryById(Integer Id, HttpSession session, Model model) {
        StudentDormitoryKey s = StudentDormitoryService.queryById(Id);
        session.setAttribute("s", s);
        model.addAttribute("s", s);
        return "StudentDormitory_edit";
    }

}
